
    /**  
    * @Title: PortalSocketUserServiceImpl.java
    * @Package com.efast.cafe.portal.service.common.impl
    * @Description: TODO(用一句话描述该文件做什么)
    * @author Administrator
    * @date 2018年10月31日
    * @version V1.0  
    */
    
package com.efast.cafe.portal.service.common.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Service;

import com.efast.cafe.framework.exception.ServiceException;
import com.efast.cafe.framework.service.CafeServiceImpl;
import com.efast.cafe.portal.dao.common.PortalSocketUserDao;
import com.efast.cafe.portal.entity.common.PortalSocketUser;
import com.efast.cafe.portal.service.common.IPortalSocketUserService;

/**
    * @ClassName: PortalSocketUserServiceImpl
    * @Description: TODO(这里用一句话描述这个类的作用)
    * @author Administrator
    * @date 2018年10月31日
    *
    */
@Service
public class PortalSocketUserServiceImpl extends CafeServiceImpl<PortalSocketUser> implements IPortalSocketUserService{

	private PortalSocketUserDao portalSocketUserDao;
	
	@Autowired
	public void setPortalSocketUserDao(PortalSocketUserDao portalSocketUserDao) {
		this.portalSocketUserDao = portalSocketUserDao;
		this.mapper = portalSocketUserDao;
	}



	@Override
	public PortalSocketUser authorize(String uid, String pwd) {
		PortalSocketUser u = new PortalSocketUser();
		u.setUid(uid);
		PortalSocketUser user = this.selectOne(u);
		if(user!=null){
			if(user.getState().intValue()==0){
				throw new ServiceException("disabled");
			}
			BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
			if(passwordEncoder.matches(pwd, user.getPwd())){
				return user;
			}
		}
		return null;
	}

}
